package com.sun.androidexerciseproject.widget.activity.ui;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import com.gyf.immersionbar.ImmersionBar;
import com.sun.androidexerciseproject.widget.R;

public class MainActivity extends AppCompatActivity {
    private Button mButton;
    private WebView mWebView;
    private AutoCompleteTextView mAutoCompleteTextView;
    private SeekBar mSeekBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LayoutInflater inflater = LayoutInflater.from(this);
        RelativeLayout parent = (RelativeLayout) inflater.inflate(R.layout.activity_main, null);
        setContentView(parent);
        ImmersionBar.with(this).navigationBarColor(R.color.colorPrimary).init();
        initWidgets();
    }

    private void initWidgets() {
        mButton = findViewById(R.id.btn_network);
        mButton.setOnClickListener(v -> mWebView.loadUrl("http://www.sohu.com"));
        mWebView = findViewById(R.id.webview);
        String[] homeTown = getResources().getStringArray(R.array.auto_text);
        mAutoCompleteTextView = findViewById(R.id.auto_text_view);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, homeTown);
        mAutoCompleteTextView.setAdapter(adapter);
        mSeekBar = findViewById(R.id.seek_bar);
        mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setMessage("Message");
                builder.setTitle("Title");
                builder.setCancelable(true);
                builder.setPositiveButton(android.R.string.ok, (dialog, which) -> dialog.dismiss());
                builder.show();
            }
        });
        Button button = (Button) findViewById(R.id.btn_scroll);
        button.setOnClickListener(v -> startActivity(new Intent(MainActivity.this, ScrollActivity.class)));
    }

    public void viewPager(View view) {
        startActivity(new Intent(this, ViewPagerActivity.class));
    }

    public void imeTest(View view) {
        startActivity(new Intent(this, IMETestActivity.class));
    }
}
